# -*- coding:utf-8 -*-
"""
# Script Name		: RomanNumber
# Author			: Jun
# Created			: 2019.1.13
# Last Modified		: 2019.1.13
# Version			: 1.0
# Modifications		: 
# Description		: 
"""
from num import num2, num1


class JunJun(object):
    def __init__(self):

        self.num1_list = [num1.ZERO, num1.ONE, num1.TWO, num1.THREE, num1.FOUR, num1.FIVE,
                          num1.SIX, num1.SEVEN, num1.EIGHT, num1.NINE, num1.ERROR]
        self.num2_list = [num2.ZERO, num2.ONE, num2.TWO, num2.THREE, num2.FOUR, num2.FIVE,
                          num2.SIX, num2.SEVEN, num2.EIGHT, num2.NINE, num2.ERROR]
        self.roman_dict = {
            "I": 1, "V": 5, "X": 10, "L": 50, "C": 100, "D": 500, "M": 1000
        }

    def size1_engine(self, arabic_num):
        """
        :param arabic_num: 经过转换后的阿拉伯数字
        :return: NULL
        """
        if arabic_num < 0:
            for i in range(5):
                print(self.num1_list[10][i], sep=" ", end="")
                print()
        else:
            numlist = list(str(arabic_num))
            for i in range(5):
                for num in numlist:
                    print(self.num1_list[int(num)][i], sep=" ", end="")
                print()

    def size2_engine(self, arabic_num):
        """
        :param arabic_num: 经过转换后的阿拉伯数字
        :return: NULL
        """
        if arabic_num < 0:
            for i in range(7):
                print(self.num2_list[10][i], sep=" ", end="")
                print()
        else:
            numlist = list(str(arabic_num))
            for i in range(7):
                for num in numlist:
                    print(self.num2_list[int(num)][i], sep=" ", end="")
                print()

    def Conversion(self, roman_num):
        """
        :param roman_num: 需要转换的罗马数字
        :return: number  转换完成的阿拉伯数字      
        """
        number = 0
        for roman in roman_num:
            number += self.roman_dict[roman]
        return number

    def engine(self, func):
        """
        :param func: 要调用的程序
        :return: func
        """
        commend = input("Please enter your order or Roman Number:")
        if commend.strip() == "set size 2":
            func = self.size2_engine
            print("set size 2 success")
            return func
        else:
            commend = commend.strip().upper()
            check = [False for i in list(commend) if i not in ["I", "V", "X", "L", "C", "D", "M"]]
            if check:
                func(-1)
                return func
            else:
                number = self.Conversion(commend)
                func(number)
                return func

    @staticmethod
    def print_menu():
        """
        :Description:打印函数。
        :return: NULL
        """
        print("* "*50)
        print("Welcome to the Roman Digital Calculator program")
        print("This program allows you to enter the following characters (case can be ignored)")
        print("eg: I、V、X、L、C、D、M")
        print("If you don't enter these numbers, the system will judge the input error.")
        print("You can type (set size 2 or set size 1) to switch the size of the output")
        print("* "*50)

    def run(self):
        """
        :Description:函数运行 
        :return: NULL
        """
        self.print_menu()
        func = self.size1_engine
        while True:
            func = self.engine(func=func)

if __name__ == '__main__':
    junjun = JunJun()
    junjun.run()
